package gdut.jmxywz.action;


import gdut.jmxywz.been.Bookmaking;
import gdut.jmxywz.been.BookmakingFile;
import gdut.jmxywz.been.Setmoney;

import gdut.jmxywz.been.Teacher;
import gdut.jmxywz.util.PageModel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;


public class BookmakingAction extends BaseAction{
	
	private  static final String  TEACHER_SESSION_KEY = "teacherSessionKey";
	private Teacher  teacher;
	
	private Bookmaking bookmaking;
	 private PageModel pageModel;
	 private int bookmakingId;
	 
		/***************分页*****************/
		private int currentPage=1;
		
		private int pageSize=5;
		
		/***************检索*****************/
		//private String searchSelect="";
		
		private String like="";
		private String where_search="";
		private String where_value="";
		//private String searchValue="";

		/**************文件上传****************/
		private List<String> files_content;
		private List<File> upload_file;       
		

		private List<String> upload_fileContentType;
		private List<String> upload_fileFileName;
		private String   savePath;
		private List<BookmakingFile> bookmakingFile ;
		/**************excel表导出导入****************/
		private File excelFile;
		private String excelFileContentType;
		private boolean checkbox;
		
	


		/***************增加*****************/
		 public String add() throws Exception{
			 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);
			 bookmaking.setTeacherByEditer(teacher);
	       boolean bool=this.getCommonService().saveObject(bookmaking);
	    	 
			 if(upload_file!=null)
			
					for(int i=0;i<upload_file.size();i++){//控制上传部分
						String extend_name=getUpload_fileFileName().get(i);
//						System.out.println(extend_name);
						int extend_name_int=extend_name.lastIndexOf(".");//截取扩展名
						extend_name=extend_name.substring(extend_name_int);
									
						java.text.DateFormat df = new java.text.SimpleDateFormat("yyyyMMddHHmmss") ;//生成时间用于重命名文件
					   String datestr = df.format(new java.util.Date()) ;
					   Random rand = new Random();//生成随机数
					   int ram = rand.nextInt(500);
						String ram_str = String.valueOf(ram);
						for(int i_i=0; ram_str.length()<6;i_i++){
							ram_str="0"+ram_str;
						}
						

						
						
						String root = ServletActionContext.getRequest().getRealPath(
								"/accessories/bookmaking/");//获得文件在服务器的绝对路径
						
						extend_name=datestr+ram_str+extend_name;//合成文件名    时间+随机数+扩展名
//						System.out.println("----文件名-:---"+extend_name+"--------------");
						 savePath=root+"\\"+extend_name;
						
//							System.out.println("----服务器保存路径-:---"+savePath+"--------------");
						 
						String fn=savePath ;
						FileOutputStream fos=new  FileOutputStream(fn);
						
						InputStream fis=new FileInputStream(upload_file.get(i));
						byte[] buffer=new byte[8192];
						int len=0;
						while((len=fis.read(buffer))>0){
						fos.write(buffer,0,len);
						
						}
//						fos.close();
//						fis.close();
						
						BookmakingFile afiles=new BookmakingFile();
									
						
//						System.out.println();
//						System.out.println("----------第--"+(i+1)+"--文件--------------");
//						System.out.println("----服务器保存路径-:---"+savePath+"--------------");
//						System.out.println("--------文件名:"+upload_fileFileName.get(i)+"--------------");
//						System.out.println("--------文件说明:"+files_content.get(i)+"--------------");
						
						afiles.setBookmakingFileUrl("/accessories/bookmaking/"+extend_name);
						afiles.setBookmakingFileName(upload_fileFileName.get(i));
						afiles.setBookmakingFileContext(files_content.get(i));
						afiles.setBookmaking(bookmaking);	
			
						//在插入附件表
						boolean b2=this.getCommonService().saveObject(afiles);
				
//				文件上传处理结束
				
		     	}

			 if(bool)
			 return SUCCESS;
			 else
				 return "error";
		 }

	 
	 
	 /***************show*****************/
		public String show()throws Exception{
			
			String hql=" from Bookmaking  where auditing != 0";
			hql = hql +" order by bookmakingId desc,auditing desc";
			pageModel=this.getCommonService().findPage(hql, null, currentPage, pageSize,"BookmakingShow.action","");
//			scientificInfo=(Info)pageModel.getList().get(0);
//			System.out.println("============================"+scientificInfo.getInfoTitle());
		
			return SUCCESS;
		}
		//最新著作
      public String show1()throws Exception{
			
			String hql=" from Bookmaking  where auditing != 0";
			hql = hql +" order by bookmakingId desc,auditing desc";
			pageModel=this.getCommonService().findPage(hql, null, currentPage, pageSize,"BookmakingSearch.action","");
//			scientificInfo=(Info)pageModel.getList().get(0);
//			System.out.println("============================"+scientificInfo.getInfoTitle());
		
			return SUCCESS;
		}
		
		
		
		/***************查找*****************/
		public String search() throws Exception {
			// TODO Auto-generated method stub
			String hql=" from Bookmaking  where auditing != 0";
			
			 String[] parem = null;
	    	  
	    	  String  search_parameter = "";
	    	  String en_where_value="";
	    	  
	    	  //
	    	  String searchValue1=where_value;
	    	  //
				HttpServletRequest request = ServletActionContext.getRequest();
				where_value=new String(request.getParameter("where_value").getBytes("ISO-8859-1"),"UTF-8");
				//
           if(!"".equals(where_value)&&where_value!=null){
	    		  
	    		  en_where_value=java.net.URLEncoder.encode(where_value, "utf-8");//URL编码转换
	    		  System.out.println("++++-- "+where_value);
	    		  
	    		  if (like.equals("like")) {
	    			  hql = hql + "  and " + where_search + " like '%"+ searchValue1 + "%' ";
	  				//hql = hql + "  and sc." + where_search + " like '%"+ searchValue1 + "%' ";
	  			} else {
	  				hql = hql + "  and " + where_search + " ='"+ searchValue1 + "' ";
	  				//hql = hql + "  and sc." + where_search + " ='"+ searchValue1 + "' ";
	  			}
	    		  
	    	  }
	    	  
	    	  hql = hql +" order by bookmakingId desc,auditing desc";
	    	  
	    	  //查询条件
	    	  
	    	  search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
	    	  
	    	  pageModel = new PageModel();
	    	  
	    	  pageModel=this.getCommonService().findPage(hql, parem, currentPage, pageSize, "BookmakingSearch.action",search_parameter);
			
			
			
			//
			//HttpServletRequest request = ServletActionContext.getRequest();
			//searchValue=new String(request.getParameter("searchValue").getBytes("ISO-8859-1"),"UTF-8");
			//
			//String searchValue1=searchValue;
			/*if (like.equals("like")) {
				hql = hql + "  and " + searchSelect + " like '%"+ searchValue1 + "%' ";
			} else {
				hql = hql + "  and " + searchSelect + " ='"+ searchValue1 + "' ";
			}
			hql = hql +" order by bookmakingId desc,auditing desc";
			pageModel=this.getCommonService().findPage(hql, null, currentPage, pageSize,"BookmakingSearch.action",searchValue1);
			*/
			return SUCCESS;
			
			
		}
		
		//最新
		public String search1() throws Exception {
			// TODO Auto-generated method stub
			String hql=" from Bookmaking  where auditing != 0";
			
			
			 String[] parem = null;
	    	  
	    	  String  search_parameter = "";
	    	  String en_where_value="";
	    	  
	    	 
				HttpServletRequest request = ServletActionContext.getRequest();
				where_value=new String(request.getParameter("where_value").getBytes("ISO-8859-1"),"UTF-8");
				 //
		    	  String searchValue1=where_value;
		    	  //
				//
           if(!"".equals(where_value)&&where_value!=null){
	    		  
	    		  en_where_value=java.net.URLEncoder.encode(where_value, "utf-8");//URL编码转换
	    		  System.out.println("++++-- "+where_value);
	    		  
	    		  if (like.equals("like")) {
	    			  hql = hql + "  and " + where_search + " like '%"+ searchValue1 + "%' ";
	  				//hql = hql + "  and sc." + where_search + " like '%"+ searchValue1 + "%' ";
	  			} else {
	  				hql = hql + "  and " + where_search + " ='"+ searchValue1 + "' ";
	  				//hql = hql + "  and sc." + where_search + " ='"+ searchValue1 + "' ";
	  			}
	    		  
	    	  }
	    	  
           hql = hql +" order by bookmakingId desc,auditing desc";
	    	  
	    	  //查询条件
	    	  
	    	  search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
	    	  
	    	  pageModel = new PageModel();
	    	  
	    	  pageModel=this.getCommonService().findPage(hql, parem, currentPage, pageSize, "BookmakingSearchList.action",search_parameter);
			
			//
			//HttpServletRequest request = ServletActionContext.getRequest();
			//searchValue=new String(request.getParameter("searchValue").getBytes("ISO-8859-1"),"UTF-8");
			//
			//String searchValue1=searchValue;
			/*if (like.equals("like")) {
				hql = hql + "  and " + searchSelect + " like '%"+ searchValue1 + "%' ";
			} else {
				hql = hql + "  and " + searchSelect + " ='"+ searchValue1 + "' ";
			}
			hql = hql +" order by bookmakingId desc,auditing desc";
			pageModel=this.getCommonService().findPage(hql, null, currentPage, pageSize,"BookmakingSearchList.action",searchValue1);
			*/
			return SUCCESS;
			
			
		}

		
		
		
		/***************详细*****************/
		public String detail() throws Exception {
			// TODO Auto-generated method stub
			String hql="from BookmakingFile where BookmakingId="+bookmakingId;
			
			bookmakingFile=this.getCommonService().findListByHql(hql, null);
			bookmaking=(Bookmaking)this.getCommonService().findByIntId(bookmakingId, "gdut.jmxywz.been.Bookmaking");
			if(bookmaking==null)
				return "error";
			else
				return SUCCESS;
		}

		
		
		
		
		/***************管理员更新预处理*****************/
		public String preUpdate() throws Exception {
			 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);
             
			// TODO Auto-generated method stub
			bookmaking=(Bookmaking)this.getCommonService().findByIntId(bookmakingId, "gdut.jmxywz.been.Bookmaking");
			bookmaking.setTeacherByAssessor(teacher);
			String hql2="from BookmakingFile where bookmakingId="+bookmakingId;
			bookmakingFile=this.getCommonService().findListByHql(hql2, null);
			
			if(bookmaking==null)
				return "error";
			else
				return SUCCESS;
		}
		/***************非管理员更新预处理*****************/
		public String preUpdateSelf() throws Exception {
			 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

			// TODO Auto-generated method stub
			bookmaking=(Bookmaking)this.getCommonService().findByIntId(bookmakingId, "gdut.jmxywz.been.Bookmaking");
			
			if(!bookmaking.getTeacherByEditer().getTeacherId().equals(teacher.getTeacherId())){
				
				System.out.println("没有修改的权限");
				
				return "error";
			}
			if(!"0".equals(bookmaking.getAuditing())){
		   		  
		   		System.out.println("已通过审核，不能在修改！");
		   		
		   		return "error";
		   	  }
		 
			String hql2="from BookmakingFile where bookmakingId="+bookmakingId;
			bookmakingFile=this.getCommonService().findListByHql(hql2, null);
			
			if(bookmaking==null)
				return "error";
			else
				return SUCCESS;
		}
		
		
		
		/***************更新*****************/
		public String update() throws Exception {
			
			Bookmaking bookmaking2=(Bookmaking)this.getCommonService().findByIntId(bookmaking.getBookmakingId(), "gdut.jmxywz.been.Bookmaking");
			bookmaking2.setBookmakingAuthor(bookmaking.getBookmakingAuthor());
			bookmaking2.setBookmakingTitle(bookmaking.getBookmakingTitle());
			bookmaking2.setPublishTime(bookmaking.getPublishTime());
			bookmaking2.setIsbn(bookmaking.getIsbn());
			bookmaking2.setPublishingCompany(bookmaking.getPublishingCompany());
		
			
			// TODO Auto-generated method stub
//			System.out.print("==========="+scientificInfoUpdate);
			boolean bl=this.getCommonService().updateObject(bookmaking2);
//			System.out.print("==========="+scientificInfoUpdate);
//			System.out.print("==========="+bl);
			
			 if(upload_file!=null)
					
					for(int i=0;i<upload_file.size();i++){//控制上传部分
						String extend_name=getUpload_fileFileName().get(i);
//						System.out.println(extend_name);
						int extend_name_int=extend_name.lastIndexOf(".");//截取扩展名
						extend_name=extend_name.substring(extend_name_int);
									
						java.text.DateFormat df = new java.text.SimpleDateFormat("yyyyMMddHHmmss") ;//生成时间用于重命名文件
					   String datestr = df.format(new java.util.Date()) ;
					   Random rand = new Random();//生成随机数
					   int ram = rand.nextInt(500);
						String ram_str = String.valueOf(ram);
						for(int i_i=0; ram_str.length()<6;i_i++){
							ram_str="0"+ram_str;
						}
						

						
						
						String root = ServletActionContext.getRequest().getRealPath(
								"/accessories/bookmaking/");//获得文件在服务器的绝对路径
						
						extend_name=datestr+ram_str+extend_name;//合成文件名    时间+随机数+扩展名
//						System.out.println("----文件名-:---"+extend_name+"--------------");
						 savePath=root+"\\"+extend_name;
						
//							System.out.println("----服务器保存路径-:---"+savePath+"--------------");
						 
						String fn=savePath ;
						FileOutputStream fos=new  FileOutputStream(fn);
						
						InputStream fis=new FileInputStream(upload_file.get(i));
						byte[] buffer=new byte[8192];
						int len=0;
						while((len=fis.read(buffer))>0){
						fos.write(buffer,0,len);
						
						}
//						fos.close();
//						fis.close();
						
						BookmakingFile afiles=new BookmakingFile();
									
						
//						System.out.println();
//						System.out.println("----------第--"+(i+1)+"--文件--------------");
//						System.out.println("----服务器保存路径-:---"+savePath+"--------------");
//						System.out.println("--------文件名:"+upload_fileFileName.get(i)+"--------------");
//						System.out.println("--------文件说明:"+files_content.get(i)+"--------------");
						
						afiles.setBookmakingFileUrl("/accessories/bookmaking/"+extend_name);
						afiles.setBookmakingFileName(upload_fileFileName.get(i));
						afiles.setBookmakingFileContext(files_content.get(i));
						afiles.setBookmaking(bookmaking);	
			
						//在插入附件表
						boolean b2=this.getCommonService().saveObject(afiles);
				
//				文件上传处理结束
				
		     	}
			if(bl)
				return SUCCESS;
			else
				return "error";
		}
		
		
		
		
		/***************删除*****************/
		public String delete() throws Exception {
			  teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

			// TODO Auto-generated method stub
			bookmaking=(Bookmaking)this.getCommonService().findByIntId(bookmakingId, "gdut.jmxywz.been.Bookmaking");
			
			if(bookmaking!=null){
				
				
				String hql="from BookmakingFile where bookmakingId="+bookmakingId;
		         
				Bookmaking bookmaking1 = new Bookmaking();
			         
				bookmaking1 =(Bookmaking) this.getCommonService().findByIntId(bookmakingId, "gdut.jmxywz.been.Bookmaking");
			   	  
			         //删除服务器上的附件
			   	  
			   	    List fileList = this.getCommonService().findListByHql(hql, null);
			   	  
			   	    Iterator iter = fileList.iterator();
			   	   
			   	    while(iter.hasNext()){
			   		  
			   	    	BookmakingFile bookmakingFile = (BookmakingFile)iter.next();
			   		  
			   		  String path = ServletActionContext.getRequest().getRealPath("/");
			   		  
			   		  path = path + bookmakingFile.getBookmakingFileUrl();
			   		  
			   		//  System.out.println("======="+path);
			   		  
			   		  this.getCommonService().deleteObject(bookmakingFile);
			   		  
			   		  this.deleteFile(path);
			   		  
			   		  //System.out.println("===文件删除===");
			   	    }
			   		  
			   		boolean bl=this.getCommonService().deleteObject(bookmaking);//删除科研著作
			   		
			   		if(bl)
						return SUCCESS;
					else
						return "error";
			   	  }
				
				
				
				else
					return "error";
			
		}
		
		/***************非管理员删除*****************/
		public String deleteSelf() throws Exception {
			  teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

			// TODO Auto-generated method stub
			bookmaking=(Bookmaking)this.getCommonService().findByIntId(bookmakingId, "gdut.jmxywz.been.Bookmaking");
			//判断是否可以删除
	  	    if(!bookmaking.getTeacherByEditer().getTeacherId().equals(teacher.getTeacherId())){
				
				System.out.println("没有删除的权限");
				
				return "error";
			}
			if(!"0".equals(bookmaking.getAuditing())){
		   		  
		   		System.out.println("已通过审核，不能在修改！");
		   		
		   		return "error";
		   	  }
			
			if(bookmaking!=null){
				
				
				String hql="from BookmakingFile where bookmakingId="+bookmakingId;
		         
				Bookmaking bookmaking1 = new Bookmaking();
			         
				bookmaking1 =(Bookmaking) this.getCommonService().findByIntId(bookmakingId, "gdut.jmxywz.been.Bookmaking");
			   	  
			         //删除服务器上的附件
			   	  
			   	    List fileList = this.getCommonService().findListByHql(hql, null);
			   	  
			   	    Iterator iter = fileList.iterator();
			   	   
			   	    while(iter.hasNext()){
			   		  
			   	    	BookmakingFile bookmakingFile = (BookmakingFile)iter.next();
			   		  
			   		  String path = ServletActionContext.getRequest().getRealPath("/");
			   		  
			   		  path = path + bookmakingFile.getBookmakingFileUrl();
			   		  
			   		  System.out.println("======="+path);
			   		  
			   		  this.getCommonService().deleteObject(bookmakingFile);
			   		  
			   		  this.deleteFile(path);
			   		  
			   		  System.out.println("===文件删除===");
			   	    }
			   		  
			   		boolean bl=this.getCommonService().deleteObject(bookmaking);//删除科研著作
			   		
			   		if(bl)
						return SUCCESS;
					else
						return "error";
			   	  }
				
				
				
				else
					return "error";
			
		}
		
		 /***
		    *  deleteFile  从服务器上删除附件
		    * @param sPath
		    * @return
		    */
			
			public  boolean deleteFile(String sPath) {   
				boolean  flag = false;   
				File   file = new File(sPath);   
			    // 路径为文件且不为空则进行删除   
			    if (file.isFile() && file.exists()) {   
			        file.delete();   
			        System.out.println("---成功从服务器删除文件---");
			        flag = true;   
			    }   
			    return flag;   
			}  
		
		
		/***************show审核信息列表*****************/
		public String auditingShow()throws Exception{
			 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

			String hql=" from Bookmaking ";
			 hql = hql +"  order by auditing asc ,bookmakingId desc";
			pageModel=this.getCommonService().findPage(hql, null, currentPage, pageSize,"BookmakingAuditingShow.action","");
//			bookmaking=(Bookmaking)pageModel.getList().get(0);
			
			return SUCCESS;
		}
		/***************show非管理员信息列表*****************/
		public String selfShow()throws Exception{
			 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);
				String hql=" from Bookmaking where teacherByEditer.teacherId="+teacher.getTeacherId();
				 hql = hql +"  order by auditing asc ,bookmakingId desc";
		
			pageModel=this.getCommonService().findPage(hql, null, currentPage, pageSize,"BookmakingSelfShow.action","");
//			bookmaking=(Bookmaking)pageModel.getList().get(0);
			
			return SUCCESS;
		}
		
		
		
		/***************Search审核列表*****************/		
		public String searchAuditing() throws Exception {
			 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

			// TODO Auto-generated method stub
			String hql="from Bookmaking";
			
			
			 String[] parem = null;
	    	  
	    	  String  search_parameter = "";
	    	  String en_where_value="";
	    	  
				HttpServletRequest request = ServletActionContext.getRequest();
				where_value=new String(request.getParameter("where_value").getBytes("ISO-8859-1"),"UTF-8");

		    	  //
		    	  String searchValue1=where_value;
		    	  //
				//
           if(!"".equals(where_value)&&where_value!=null){
	    		  
	    		  en_where_value=java.net.URLEncoder.encode(where_value, "utf-8");//URL编码转换
	    		  System.out.println("++++-- "+where_value);
	    		  
	    		  if (like.equals("like")) {
	    			  hql = hql + "  where " + where_search + " like '%"+ searchValue1 + "%' ";
	  				//hql = hql + "  and sc." + where_search + " like '%"+ searchValue1 + "%' ";
	  			} else {
	  				hql = hql + "  where " + where_search + " ='"+ searchValue1 + "' ";
	  				//hql = hql + "  and sc." + where_search + " ='"+ searchValue1 + "' ";
	  			}
	    		  
	    	  }
	    	  
           hql = hql +"  order by auditing asc ,bookmakingId desc";
	    	  
	    	  //查询条件
	    	  
	    	  search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
	    	  
	    	  pageModel = new PageModel();
	    	  
	    	  pageModel=this.getCommonService().findPage(hql, parem, currentPage, pageSize, "BookmakingSearchAuditing.action",search_parameter);
			
			//
			//HttpServletRequest request = ServletActionContext.getRequest();
			//searchValue=new String(request.getParameter("searchValue").getBytes("ISO-8859-1"),"UTF-8");
			//
			/*String searchValue1=searchValue;
			if (like.equals("like")) {
				hql = hql + "  where " + searchSelect + " like '%"+ searchValue1 + "%' ";
			} else {
				hql = hql + "  where " + searchSelect + " ='"+ searchValue1 + "' ";
			}
			 hql = hql +"  order by auditing asc ,bookmakingId desc";
			pageModel=this.getCommonService().findPage(hql, null, currentPage, pageSize,"BookmakingSearchAuditing.action",searchValue1);*/
			
			return SUCCESS;
		}
		
		
		
		/***************Search审核列表*****************/		
		public String searchSelf() throws Exception {
			 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

			// TODO Auto-generated method stub
			String hql="from Bookmaking";
			
			 String[] parem = null;
	    	  
	    	  String  search_parameter = "";
	    	  String en_where_value="";
	    	  
	    	  //
	    	  String searchValue1=where_value;
	    	  //
				HttpServletRequest request = ServletActionContext.getRequest();
				where_value=new String(request.getParameter("where_value").getBytes("ISO-8859-1"),"UTF-8");
				//
           if(!"".equals(where_value)&&where_value!=null){
	    		  
	    		  en_where_value=java.net.URLEncoder.encode(where_value, "utf-8");//URL编码转换
	    		  System.out.println("++++-- "+where_value);
	    		  
	    		  if (like.equals("like")) {
	    			  hql = hql + "  where " + where_search + " like '%"+ searchValue1 + "%' ";
	  				//hql = hql + "  and sc." + where_search + " like '%"+ searchValue1 + "%' ";
	  			} else {
	  				hql = hql + "  where " + where_search + " ='"+ searchValue1 + "' ";
	  				//hql = hql + "  and sc." + where_search + " ='"+ searchValue1 + "' ";
	  			}
	    		  
	    	  }
	    	  
           hql = hql +"  order by auditing asc ,bookmakingId desc";
	    	  
	    	  //查询条件
	    	  
	    	  search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
	    	  
	    	  pageModel = new PageModel();
	    	  
	    	  pageModel=this.getCommonService().findPage(hql, parem, currentPage, pageSize, "BookmakingSearchSelf.action",search_parameter);
			
			//
			//HttpServletRequest request = ServletActionContext.getRequest();
			//searchValue=new String(request.getParameter("searchValue").getBytes("ISO-8859-1"),"UTF-8");
			//
			/*String searchValue1=searchValue;
			if (like.equals("like")) {
				hql = hql + "  where " + searchSelect + " like '%"+ searchValue1 + "%' ";
			} else {
				hql = hql + "  where " + searchSelect + " ='"+ searchValue1 + "' ";
			}
			 hql = hql +"  order by auditing asc ,bookmakingId desc";
			pageModel=this.getCommonService().findPage(hql, null, currentPage, pageSize,"BookmakingSearchSelf.action",searchValue1);
			*/
			return SUCCESS;
		}
	//新加
		public String searchSelf1() throws Exception {
			 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

			// TODO Auto-generated method stub
			String hql="from Bookmaking";
			
			 String[] parem = null;
	    	  
	    	  String  search_parameter = "";
	    	  String en_where_value="";
	    	  
	    	 
				HttpServletRequest request = ServletActionContext.getRequest();
				where_value=new String(request.getParameter("where_value").getBytes("ISO-8859-1"),"UTF-8");
				 //
		    	  String searchValue1=where_value;
		    	  //
				//
           if(!"".equals(where_value)&&where_value!=null){
	    		  
	    		  en_where_value=java.net.URLEncoder.encode(where_value, "utf-8");//URL编码转换
	    		  System.out.println("++++-- "+where_value);
	    		  
	    		  if (like.equals("like")) {
	    			  hql = hql + "  where " + where_search + " like '%"+ searchValue1 + "%' ";
	  				//hql = hql + "  and sc." + where_search + " like '%"+ searchValue1 + "%' ";
	  			} else {
	  				hql = hql + "  where " + where_search + " ='"+ searchValue1 + "' ";
	  				//hql = hql + "  and sc." + where_search + " ='"+ searchValue1 + "' ";
	  			}
	    		  
	    	  }
	    	  
           hql = hql +"  order by auditing asc ,bookmakingId desc";
	    	  
	    	  //查询条件
	    	  
	    	  search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
	    	  
	    	  pageModel = new PageModel();
	    	  
	    	  pageModel=this.getCommonService().findPage(hql, parem, currentPage, pageSize, "BookmakingSearchSelf1.action",search_parameter);
			
			//
			//HttpServletRequest request = ServletActionContext.getRequest();
			//searchValue=new String(request.getParameter("searchValue").getBytes("ISO-8859-1"),"UTF-8");
			//
			/*String searchValue1=searchValue;
			if (like.equals("like")) {
				hql = hql + "  where " + searchSelect + " like '%"+ searchValue1 + "%' ";
			} else {
				hql = hql + "  where " + searchSelect + " ='"+ searchValue1 + "' ";
			}
			 hql = hql +"  order by auditing asc ,bookmakingId desc";
			pageModel=this.getCommonService().findPage(hql, null, currentPage, pageSize,"BookmakingSearchSelf1.action",searchValue1);*/
			
			return SUCCESS;
		}
		
		
		
		   /***
	     *   inside 对内公布
	     */
		  public String inside() throws Exception{
				 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

	    	  
			  bookmaking=(Bookmaking)this.getCommonService().findByIntId(bookmakingId, "gdut.jmxywz.been.Bookmaking");
	    	  //将信息审核为对院内公布 ，即设置auditing为1；
			 if(bookmaking!=null){
				 bookmaking.setAuditing("1");
				 bookmaking.setTeacherByAssessor(teacher);
			  boolean bl=this.getCommonService().updateObject(bookmaking);
			   if(bl){  
			  return SUCCESS;
			   }
			   return "error";
			 }
			 return "error";
		  }
		  
		
	    /***
	     *   outside 对外公布
	     */
	    public String outside() throws Exception{
			 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

	    	bookmaking=(Bookmaking)this.getCommonService().findByIntId(bookmakingId, "gdut.jmxywz.been.Bookmaking");
	    	  //将信息审核为对院内公布 ，即设置auditing为1；
			 if(bookmaking!=null){
				 bookmaking.setAuditing("2");
				 bookmaking.setTeacherByAssessor(teacher);
			  boolean bl=this.getCommonService().updateObject(bookmaking);
			   if(bl){  
			  return SUCCESS;
			   }
			   return "error";
			 }
			 return "error";
		  }
		
		/***
		 * 
		 *    notAllow 不通过
		 */
	    public String notAllow() throws Exception{
			 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

	    	bookmaking=(Bookmaking)this.getCommonService().findByIntId(bookmakingId, "gdut.jmxywz.been.Bookmaking");
	    	  //将信息审核为对院内公布 ，即设置auditing为1；
			 if(bookmaking!=null){
				 bookmaking.setAuditing("3");
				 bookmaking.setTeacherByAssessor(teacher);
			  boolean bl=this.getCommonService().updateObject(bookmaking);
			   if(bl){  
			  return SUCCESS;
			   }
			   return "error";
			 }
			 return "error";
		  }
		
	    
	    
		
		/***
		 * 
		 *    rollBack 未审核
		 */
	    public String rollBack() throws Exception{
			 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

	    	bookmaking=(Bookmaking)this.getCommonService().findByIntId(bookmakingId, "gdut.jmxywz.been.Bookmaking");
	    	  //将信息审核为对院内公布 ，即设置auditing为1；
			 if(bookmaking!=null){
				 bookmaking.setAuditing("0");
				 bookmaking.setTeacherByAssessor(teacher);
			  boolean bl=this.getCommonService().updateObject(bookmaking);
			   if(bl){  
			  return SUCCESS;
			   }
			   return "error";
			 }
			 return "error";
	  	  }

		
	    public String importExcel() throws Exception {
			  teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);
	    	// TODO Auto-generated method stub
			if(excelFile==null)
			{
				return "error";
				}
					

	    	int count=0;
			try{
			FileInputStream fis=new FileInputStream(excelFile);
			jxl.Workbook jwb=Workbook.getWorkbook(fis);
			int sheets=jwb.getNumberOfSheets();
			for(int i=0;i<sheets;i++){
				Sheet rs=jwb.getSheet(i);
				int columnNum=rs.getColumns();
				int rowNum=rs.getRows();
				if(rowNum>0&&columnNum!=5){
					System.out.println("--------------------导入格式不对----------------------");
					return "error";
				}
				Cell crl;
				for(int row=1;row<rowNum;row++){
					crl=rs.getCell(0, row);
//					String hql="from Bookmaking stc where stc.isbn='"+crl.getContents()+"'";
//					List<Bookmaking> aa=this.getCommonService().findListByHql(hql, null);

	                 boolean bl;
	             
//					if(aa.size()==0){//项目未存在
						
						
						
						    bookmaking=new Bookmaking();
	                        bookmaking.setIsbn(crl.getContents());
	                        
	                        crl=rs.getCell(1,row);
	                        bookmaking.setBookmakingTitle(crl.getContents());
	                        crl=rs.getCell(2,row);
	                        bookmaking.setBookmakingAuthor(crl.getContents());
	                        crl=rs.getCell(3,row);
	                        bookmaking.setPublishingCompany(crl.getContents());
	                        crl=rs.getCell(4,row);
	                        bookmaking.setPublishTime(crl.getContents());
	                        System.out.println("---"+crl.getContents());
	                        
	                      
	                        bookmaking.setTeacherByEditer(teacher);
	                        bookmaking.setAuditing("0");
						bl=this.getCommonService().saveObject(bookmaking);//不存在该项目

						if(!bl){
							System.out.println("------------------存入数据库出错-------------------");
						}
						
						count++;
						
					}
					
//					if(aa.size()!=0){//项目已存在
//							
//						
//						
//						if(checkbox&&aa.get(0).getAuditing().equals("0")){//判断是否对已存在项目进行更新
//							//对已存在项目进行更新	
//							
//							bookmaking=aa.get(0);
//							 bookmaking.setIsbn(crl.getContents());
//		                        
//		                        crl=rs.getCell(1,row);
//		                        bookmaking.setBookmakingTitle(crl.getContents());
//		                        crl=rs.getCell(2,row);
//		                        bookmaking.setBookmakingAuthor(crl.getContents());
//		                        crl=rs.getCell(3,row);
//		                        bookmaking.setPublishingCompany(crl.getContents());
//		                        crl=rs.getCell(4,row);
//		                        bookmaking.setPublishTime(crl.getContents());
//		                      
//		                        
//		                      
//		                        bookmaking.setTeacherByEditer(teacher);
//		                        bookmaking.setAuditing("0");
//							
//							bl=this.getCommonService().updateObject(bookmaking);//对已存在该项目更新
//						
//							if(!bl){
//								System.out.println("------------------存入数据库出错-------------------");
//							}
//							
//							count++;
//						}
//						
//						else{
//							System.out.print("项目已存在，但不做更新");//不做任何更新
//						}
//						
//					}
//				}
			}
			System.out.println("=================一共导入数据数：================="+count);
			jwb.close();
			fis.close();
			}catch(Exception e){
				e.printStackTrace();
			}
			return SUCCESS;
		}
		
	    //管理员导出Excel
	    public void exportExcel() throws Exception {
	    	
	    	
	    	// TODO Auto-generated method stub
			try{
				String[] str=new String[]{"著作名称","第一作者","出版社","出版时间","ISBN","发布人","审核状态（0==未审核，1==院内公开，2==对外公开,3==审核不通过）","审核信息"};
				List list;
				
					String hql="from Bookmaking";
					list=this.getCommonService().findListByHql(hql, null);
				
				
				
				HttpServletResponse response=ServletActionContext.getResponse();
				response.reset();
				response.setContentType("application/vnd.ms-excel");
				response.setContentType("APPLICATION/OCTET-STREAM ");
				response.setHeader("Content-Disposition","attachment; filename="+java.net.URLEncoder.encode("科研著作.xls","UTF-8"));
				WritableWorkbook wwb=Workbook.createWorkbook(response.getOutputStream());
				WritableSheet sheet=wwb.createSheet("sheet1", 0);
				sheet.setColumnView(0, 20);
				sheet.setColumnView(1, 20);
				sheet.setColumnView(2, 20);
				sheet.setColumnView(3, 20);
				sheet.setColumnView(11, 20);
				Label label=null;
				for(int i=0;i<str.length;i++){
					label=new Label(i,0,str[i]);
					sheet.addCell(label);
				}
				for(int i=0;i<list.size();i++){
					bookmaking=(Bookmaking)list.get(i);
					
					label = new Label(0, i+1, bookmaking.getBookmakingTitle());
					sheet.addCell(label);
					label = new Label(1, i+1, bookmaking.getBookmakingAuthor());
					sheet.addCell(label);
					label = new Label(2, i+1, bookmaking.getPublishingCompany());
					sheet.addCell(label);
				  //label = new Label(3, i+1, new SimpleDateFormat("yyyy-MM-dd").format(bookmaking.getPublishTime()));
					label = new Label(3, i+1, bookmaking.getPublishTime());
					sheet.addCell(label);
					label = new Label(4, i+1, bookmaking.getIsbn());
					sheet.addCell(label);
					if(bookmaking.getTeacherByEditer().getTeacherName()!=null&&!"".equals(bookmaking.getTeacherByEditer().getTeacherName())){
				    label = new Label(5, i+1, bookmaking.getTeacherByEditer().getTeacherName());
				    sheet.addCell(label);
				    }
					label = new Label(6, i+1, bookmaking.getAuditing());
					sheet.addCell(label);
//					label = new Label(11, i+1, bookmaking.getAssessor().getTeacherName());
//					sheet.addCell(label);
					label = new Label(7, i+1, bookmaking.getAssessorInfo());
					sheet.addCell(label);
			
				}
				wwb.write();
				wwb.close();
				
			}catch(Exception e){
				e.printStackTrace();
			}
			
		}
	    
	    //非管理员导出Excel
	 public void exportSelfExcel() throws Exception {
		 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);


			String hql=" from Bookmaking where teacherByEditer.teacherId="+teacher.getTeacherId();
	    	
	    	// TODO Auto-generated method stub
			try{
				String[] str=new String[]{"著作名称","第一作者","出版社","出版时间","ISBN","发布人","审核状态（0==未审核，1==院内公开，2==对外公开,3==审核不通过）","审核信息"};
				List list;
				
					
					list=this.getCommonService().findListByHql(hql, null);
				
				
			
				HttpServletResponse response=ServletActionContext.getResponse();
				response.reset();
				response.setContentType("application/vnd.ms-excel");
				response.setContentType("APPLICATION/OCTET-STREAM ");
				response.setHeader("Content-Disposition","attachment; filename="+java.net.URLEncoder.encode("科研著作.xls","UTF-8"));
				WritableWorkbook wwb=Workbook.createWorkbook(response.getOutputStream());
				WritableSheet sheet=wwb.createSheet("sheet1", 0);
				sheet.setColumnView(0, 20);
				sheet.setColumnView(1, 20);
				sheet.setColumnView(2, 20);
				sheet.setColumnView(3, 20);
				sheet.setColumnView(11, 20);
				Label label=null;
				for(int i=0;i<str.length;i++){
					label=new Label(i,0,str[i]);
					sheet.addCell(label);
				}
				for(int i=0;i<list.size();i++){
					bookmaking=(Bookmaking)list.get(i);
					
					label = new Label(0, i+1, bookmaking.getBookmakingTitle());
					sheet.addCell(label);
					label = new Label(1, i+1, bookmaking.getBookmakingAuthor());
					sheet.addCell(label);
					label = new Label(2, i+1, bookmaking.getPublishingCompany());
					sheet.addCell(label);
					//label = new Label(3, i+1, new SimpleDateFormat("yyyy-MM-dd").format(bookmaking.getPublishTime()));
					label = new Label(3, i+1, bookmaking.getPublishTime());
					sheet.addCell(label);
					label = new Label(4, i+1, bookmaking.getIsbn());
					sheet.addCell(label);
					label = new Label(5, i+1, bookmaking.getTeacherByEditer().getTeacherName());
					
					sheet.addCell(label);
					label = new Label(6, i+1, bookmaking.getAuditing());
					sheet.addCell(label);
//					label = new Label(11, i+1, bookmaking.getAssessor().getTeacherName());
//					sheet.addCell(label);
					label = new Label(7, i+1, bookmaking.getAssessorInfo());
					sheet.addCell(label);
			
				}
				wwb.write();
				wwb.close();
				
			}catch(Exception e){
				e.printStackTrace();
			}
			
		}
	    
	    
	    
	    
	    
	    
	    
	    
	    

		public Bookmaking getBookmaking() {
			return bookmaking;
		}



		public void setBookmaking(Bookmaking bookmaking) {
			this.bookmaking = bookmaking;
		}



		public PageModel getPageModel() {
			return pageModel;
		}



		public void setPageModel(PageModel pageModel) {
			this.pageModel = pageModel;
		}



		public int getBookmakingId() {
			return bookmakingId;
		}



		public void setBookmakingId(int bookmakingId) {
			this.bookmakingId = bookmakingId;
		}



		public int getCurrentPage() {
			return currentPage;
		}



		public void setCurrentPage(int currentPage) {
			this.currentPage = currentPage;
		}



		public int getPageSize() {
			return pageSize;
		}



		public void setPageSize(int pageSize) {
			this.pageSize = pageSize;
		}



		/*public String getSearchSelect() {
			return searchSelect;
		}



		public void setSearchSelect(String searchSelect) {
			this.searchSelect = searchSelect;
		}*/



		public String getLike() {
			return like;
		}



		public void setLike(String like) {
			this.like = like;
		}



	/*	public String getSearchValue() {
			return searchValue;
		}



		public void setSearchValue(String searchValue) {
			this.searchValue = searchValue;
		}*/



		public List<String> getFiles_content() {
			return files_content;
		}



		public void setFiles_content(List<String> files_content) {
			this.files_content = files_content;
		}



		public List<File> getUpload_file() {
			return upload_file;
		}



		public void setUpload_file(List<File> upload_file) {
			this.upload_file = upload_file;
		}



		public List<String> getUpload_fileContentType() {
			return upload_fileContentType;
		}



		public void setUpload_fileContentType(List<String> upload_fileContentType) {
			this.upload_fileContentType = upload_fileContentType;
		}



		public List<String> getUpload_fileFileName() {
			return upload_fileFileName;
		}



		public void setUpload_fileFileName(List<String> upload_fileFileName) {
			this.upload_fileFileName = upload_fileFileName;
		}



		public String getSavePath() {
			return savePath;
		}



		public void setSavePath(String savePath) {
			this.savePath = savePath;
		}



		public List<BookmakingFile> getBookmakingFile() {
			return bookmakingFile;
		}



		public void setBookmakingFile(List<BookmakingFile> bookmakingFile) {
			this.bookmakingFile = bookmakingFile;
		}



		public Teacher getTeacher() {
			return teacher;
		}



		public void setTeacher(Teacher teacher) {
			this.teacher = teacher;
		}



		public File getExcelFile() {
			return excelFile;
		}



		public void setExcelFile(File excelFile) {
			this.excelFile = excelFile;
		}



		public String getExcelFileContentType() {
			return excelFileContentType;
		}



		public void setExcelFileContentType(String excelFileContentType) {
			this.excelFileContentType = excelFileContentType;
		}



		public boolean isCheckbox() {
			return checkbox;
		}



		public void setCheckbox(boolean checkbox) {
			this.checkbox = checkbox;
		}



		public String getWhere_search() {
			return where_search;
		}



		public void setWhere_search(String whereSearch) {
			where_search = whereSearch;
		}



		public String getWhere_value() {
			return where_value;
		}



		public void setWhere_value(String whereValue) {
			where_value = whereValue;
		}



		



	    

	    
	    
	    

		
		
		
		
		
		
		
	
}
